package com.xzz.mq.consumer;

import com.alibaba.fastjson.JSON;
import com.xzz.dto.PayResultDto;
import com.xzz.service.ICourseUserLearnService;
import io.netty.util.CharsetUtil;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        consumerGroup = "service-course-consumer",
        topic="topic-pay",
        selectorExpression="tag-pay",
        messageModel= MessageModel.BROADCASTING   //广播模式： 一个消息可以被多个人同时消费
    )
public class CourseConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private ICourseUserLearnService courseUserLearnService;

    @Override
    public void onMessage(MessageExt message) {
        String msg = new String(message.getBody(), CharsetUtil.UTF_8);
        PayResultDto payResultDto = JSON.parseObject(msg, PayResultDto.class);
        courseUserLearnService.updateCourseUserLearn(payResultDto);
    }
}